
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mytools;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.sql.SQLException;

/**

 *

 * @author wl

 */
public class useroperation extends ActionSupport {

    private int userid;
    private user user;
    private String username;
    private String password;
    private String email;
    private userDAO ud;
    private user adduser;
    private String repassword;

    public useroperation() {
    }

    public String useradd() throws Exception {
        setUd(new userDAO());
        int i = getUd().saveUser(this.getAdduser());
        if (i == 1) {
            return SUCCESS;
        } else {
            return ERROR;
        }
    }

    public String userdelete() throws Exception {
        setUd(new userDAO());
        int i = getUd().deleteUser(getUserid());
        if (i == 1) {
            return SUCCESS;
        } else {
            return ERROR;
        }

    }

    public String useredit() throws Exception {
        user user = new user();
        user.setUserid(getUserid());
        user.setPassword(getPassword());
        user.setUsername(getUsername());
        user.setEmail(getEmail());
        userDAO ud = new userDAO();
        int i = ud.updateuser(user);
        if (i > 0) {
            ActionContext actioncontext = ActionContext.getContext();
            actioncontext.getSession().put("username", username);
            actioncontext.getSession().put("password", password);
            actioncontext.getSession().put("email", user.getEmail());
            actioncontext.getSession().put("userid", user.getUserid());
            actioncontext.getSession().put("qx", user.getQx());
            return SUCCESS;
        } else {
            return INPUT;
        }
    }

    public String userview() throws Exception {
        userDAO ud = new userDAO();
        setUser(ud.getuser(getUserid()));
        return SUCCESS;
    }

    public String execute() throws Exception {

        return SUCCESS;

    }

    /**
     * @return the userid
     */
    public int getUserid() {
        return userid;
    }

    /**
     * @param userid the userid to set
     */
    public void setUserid(int userid) {
        this.userid = userid;
    }

    /**
     * @return the user
     */
    public user getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(user user) {
        this.user = user;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the ud
     */
    public userDAO getUd() {
        return ud;
    }

    /**
     * @param ud the ud to set
     */
    public void setUd(userDAO ud) {
        this.ud = ud;
    }

    /**
     * @return the adduser
     */
    public user getAdduser() {
        return adduser;
    }

    /**
     * @param adduser the adduser to set
     */
    public void setAdduser(user adduser) {
        this.adduser = adduser;
    }

    /**
     * @return the repassword
     */
    public String getRepassword() {
        return repassword;
    }

    /**
     * @param repassword the repassword to set
     */
    public void setRepassword(String repassword) {
        this.repassword = repassword;
    }
}
